using UnityEngine;
using System.Collections;

public class Door : MonoBehaviour 
{
	public int num_switches_req;
	public GameObject textPrefab;
	
	private int num_switches = 0;
	
	public void SwitchActivated ()
	{
		++num_switches;
		
		if (num_switches == num_switches_req)
			StartCoroutine ("Activate");
	}
	
	private IEnumerator Activate ()
	{
		while (transform.localScale.x > 0.2)
		{
			transform.localScale = transform.localScale * 3 / 4;
			yield return null;
		}
		
		Destroy (gameObject);
	}
	
	public void OnCollisionEnter (Collision other)
	{
		/*
		if (other.gameObject.layer == 9)
		{
			GameObject text = Instantiate (textPrefab, transform.position, Quaternion.identity) as GameObject;
			text.GetComponent <TextMesh> ().text = "Need " + (num_switches_req - num_switches) + " more switches!";
		}
		*/
	}
}